An extended introduction to Linux

An extended introduction to Linux

A reminder of basic work conveniences

As part of working with the terminal, it is useful to recall some useful “tricks”:


System help

In Linux, system help is available for each command, describing various aspects and uses of the tool and available switches. One mechanism for displaying help files is to call a command with the --help switch, such as:

ls --help

causes a description of the operation of all switches, references to external documentation and other useful information to be displayed.

More extensive command documentation can be obtained by calling:

man command_name

This launches an interactive help file browser for the specified program or service. The system help is displayed using the more viewer, which is operated with the following keyboard commands:

Network information

The ip command allows you to obtain information about the current status of network interfaces (including the computer’s IP address).


🛠🔥 Task 1 🛠🔥

Familiarize yourself with the help for the ip command. Using especially the “EXAMPLES” section, display the current addresses of the computer’s network interfaces.


File handling

Basic file handling operations can be performed using the following commands:

A useful switch for the cp command is the -r switch, which is used to copy entire directory structures.

A useful switch for the rm command is the -r switch, which is used to delete entire directory structures.

Commands for files (and directories) can also be issued using so-called generalization patterns, which are created using the following operators:

* - replaces any string of characters (including empty),

? - replaces exactly one arbitrary character,

[<characters>] - replaces exactly one character from the specified range, e.g.: [xyz].

[^<characters>] - the ^ character at the beginning denotes the complement of the set, so for example, [^xyz], denotes any character that is not x, y and z.

Here are sample commands using generalization patterns:

cp ./*.txt ~ - copies all files with the extension .txt from the current directory to the user’s home directory,

rm ~/[0-9]* - deleting all files from the home directory whose name begins with a digit.

Text editors nano, vim.

When working with systems that do not have a graphical environment or through a remote terminal, it is often necessary to edit text files from the terminal. Efficient editing of text files is possible with console editors such as Emacs, Vim or Nano.

People who use such editors on a daily basis know plenty of shortcuts and tricks that make working with such a program more efficient than with a graphical editor.

Nano

For occasional editing of files, such as configuration files, the Nano program is the easiest to use. It offers a quasi-graphical interface with keyboard shortcut prompts.

Example usage (if the file does not exist, it will be created):

nano file.txt

Key shortcuts:

Vim/Neovim

More efficient (but requiring some preliminary knowledge) file editing is possible in the Vim editor. There is also an alternative version of it: Neovim.

Example usage (if the file does not exist, it will be created):

vim file.txt

or for the Neovim version:

nvim file.txt

The most important keyboard shortcuts:

Commands (approved with enter):


🛠🔥 Task 2 🛠🔥.

Using Vim edit any text file.

🛠🔥 Task 3 🛠🔥

Measure the editing time of any file using the time command:

time vim file.txt

Shutting down, restarting and pausing the computer

On systems without a graphical user interface (so-called headless systems), it will be useful to know the commands to safely manage the operation of the machine.

The vast majority of Linux distributions use the system daemon systemd. In this regard, it is useful to know the commands:

Putting the device to sleep is supported on personal computers, but may not be implemented on single-board computers (for example, RaspberryPi).

There are shortcut versions (so-called aliases) for the mentioned main commands:


🛠🔥 Task 4 🛠🔥.

Test the operation of the systemctl suspend command.


Installing packages

In Linux distributions, software is installed from central repositories. Avoid “cluttering” the system with external installers downloaded from websites (for example, in the form of .run files).

In the Ubuntu distribution, the apt utility is used to install packages. Some programs (usually windows-based) are also available as snap packages. Ubuntu has a graphical application “store” called Software.


🛠🔥 Task 5 🛠🔥.

Run the apt --help command. Familiarize yourself with the available options. Try to search for any package (for example, neovim).


Remote access to devices

Linux is equipped with tools to remotely access another device’s console and transfer files.

ssh command.

The ssh command is used to remotely access another device. The syntax of the command is as follows:

ssh <user>@<address>

For example:

ssh put@127.0.0.1

will connect us to our own computer.

If the username on the remote machine is identical to our username we can skip it in the command:

ssh 127.0.0.1

🛠🔥 Task 6 🛠🔥

Ask your neighboring colleagues for their IP address. Connect to their computer and turn it off.

NOTE 1: account password is put.

NOTE 2: with remote access, you may need to run the command to shut down the computer as an administrator - you can precede it with the sudo command.


Transfer files between devices

The basic command for transferring files between devices is scp. The syntax is a combination of cp and ssh:

scp <local_file> <user>@<address>:<target_directory>
scp -r <local_directory> <user>@<address>:<target_directory>

scp <user>@<address>:<remote_file> <local_directory>
scp -r <user>@<address>:<remote_directory> <local_directory>

🛠🔥 Task 7 🛠🔥

Download any file and directory from another computer. Change its contents and upload it back.


rsync tool.

The rsync tool is used for incremental (allows resuming) transfer of files and/or directories. It is very well suited for transferring large amounts of data. There are very many options for its configuration, but in most cases the following syntax will work well for transfer:

rsync -PHAXphax <local_directory> <user>@<address>:<target_directory>
rsync -PHAXphax <user>@<address>:<remote_file> <local_directory>

🛠🔥 Task 8 🛠🔥

Check what the above flags of the rsync tool mean. Use the command to transfer the selected directory.